﻿#include "WebSocketClientAcceptor.h"

#include "ace/Service_Object.h"
#include "ace/Svc_Handler.h"
#include "ace/Service_Config.h"

#include "ace/Get_Opt.h"
#include "ace/Configuration.h"


int WebSocketClientAcceptor::init (int argc, ACE_TCHAR *argv[]){
  ACE_INET_Addr sis ;
  ACE_Get_Opt   get_opt (argc, argv, ACE_TEXT("tp:"), 0);
  this->thread_per_connection_=false;
  for (int c; (c = get_opt ()) != -1; )
     switch (c)
       {
       case 'p':
         sis.set (ACE_OS::atoi (get_opt.opt_arg ()));
         break;
	   case 't':
		 this->thread_per_connection_=true;
		 break;
       default:
         break;
       }
   if (this->open (sis,ACE_Reactor::instance ()) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,"%p\n","open"),-1);
   
  return 0;
}

int WebSocketClientAcceptor::fini (void)
{
	//关闭acceptor的socket。停止监听。
	int ret=super::fini();
	return ret;
}

ACE_FACTORY_DEFINE (ACE_Local_Service, WebSocketClientAcceptor)

ACE_STATIC_SVC_DEFINE (WebSocketClientAcceptor,
                       ACE_TEXT ("WebSocketClientAcceptor"),
                       ACE_SVC_OBJ_T,
                       &ACE_SVC_NAME (WebSocketClientAcceptor),
                       ACE_Service_Type::DELETE_THIS |
                       ACE_Service_Type::DELETE_OBJ,
                       0)  // Service not initially active

ACE_STATIC_SVC_REQUIRE (WebSocketClientAcceptor)



